<?php

/**
 * 充值
 *
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/21
 * Time: 上午12:42
 */
class Recharge extends MY_Public_Api_Controller
{
    public function index()
    {
        $uid = (int)$this->input->get_post('uid');


        $this->load->service('finance/service_finance_recharge');
        $data = $this->service_finance_recharge->index($uid);


        $this->json_output($data['data'], $data['status']);
    }
    
    
    public function applepay()
    {
    	$uid     = $this->uid;
    	$aid     = (int)$this->input->get_post('aid');
    	$amount  = (double)$this->input->get_post('amount');
    	$receipt =  $this->input->get_post('receipt');
    
    	$this->load->service('finance/service_finance_recharge');
    	$data = $this->service_finance_recharge->applepay($uid, $aid, $amount, $receipt);
    	
    	$this->json_output($data['data'], $data['status']);
    }


    public function request()
    {
        $uid         = $this->uid;
        $amount      = (int)$this->input->get_post('amount');
        $aid         = (int)$this->input->get_post('aid');
        $pay_channel = (int)$this->input->get_post('channel');
        $client      = (int)$this->input->get_post('client');
        $app_name    = $this->input->get_post('app_name');
        $package_name = $this->input->get_post('package_name');

        $aid         = $amount ? $amount : $aid;


        $this->load->service('finance/service_finance_recharge');
        $data = $this->service_finance_recharge->request($uid, $aid, $pay_channel, $client,$app_name,$package_name);


        //p($data);
        //echo $data['data']['url'];exit;
        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 支付 宝回调的地址
     */
    public function alipay_response()
    {
        $this->load->service('finance/service_finance_recharge');
        $data = $this->service_finance_recharge->response(1);


        $this->json_output($data['data'], $data['status']);
    }
    
    /**
     * 微信支付回调的地址
     */
    public function wx_response()
    {
    	$this->load->service('finance/service_finance_recharge');
    	$data = $this->service_finance_recharge->response(2);
    
    	$this->json_output($data['data'], $data['status']);
    }


    /**
     * 查询支付状态
     */
    public function status()
    {
        $cid = (int)$this->input->get_post('cid');


        $this->load->service('finance/service_finance_recharge');
        $data = $this->service_finance_recharge->status($cid);


        $this->json_output($data['data'], $data['status']);
    }
}